from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext import db

import model
from util import templated, admin_only

class AdminPage(webapp.RequestHandler):
    @admin_only
    @templated('admin.html')
    def get(self):
        return {}

    @admin_only
    @templated('admin.html')
    def post(self):
        if self.request.get('delete_beverage_db'):
            beverages = list(model.Beverage.all())
            for beverage in beverages:
                beverage.delete()
            msg = 'Beverages deleted.'
        elif self.request.get('load_beverage_db'):
            import beverages_db
            for beverage in beverages_db.entities:
                beverage.put()
            msg = 'Beverages loaded.'
        elif self.request.get('delete_intakes'):
            intakes = list(model.Intake.all())
            for intake in intakes:
                db.delete(intake)
            msg = 'Intakes deleted.'

        return { 'message': msg }
